package com.chris.homecare.components
{
	import com.chris.homecare.TextureAtlasManager;
	import com.chris.homecare.utils.CommonUtils;
	
	import flash.text.TextFormat;
	import flash.text.engine.ElementFormat;
	import flash.text.engine.FontDescription;
	
	import feathers.controls.Label;
	import feathers.controls.LayoutGroup;
	import feathers.controls.text.TextFieldTextRenderer;
	import feathers.core.ITextRenderer;
	import feathers.display.Scale3Image;
	import feathers.textures.Scale3Textures;
	
	import starling.display.Image;
	import starling.textures.Texture;
	
	public class BreadcrumbComponenet extends LayoutGroup
	{
		private var header1:String;
		private var header2:String;
		private var header3:String;
		
		private var bredcrumbLabel1:Label;
		private var bredcrumbLabel2:Label;
		private var bredcrumbLabel3:Label;
		
		private var bredcrumb1Image:Scale3Image;
		private var bredcrumbBackground:Image;
		private var bredcrumb2Image:Scale3Image;

		private var fontDes:FontDescription;

		private var elementFormat:ElementFormat;
		
		public function BreadcrumbComponenet(header1:String = "TestString", header2:String = "", header3:String = "")
		{
			super();
			this.header1 = header1;
			this.header2 = header2;
			this.header3 = header3;
		}
		
		override protected function initialize():void
		{
			bredcrumbBackground = new Image(TextureAtlasManager.getAtlas().getTexture("bredcrumbBack"));
			addChild(bredcrumbBackground);
			
			
			if(header2 != "")
			{
				const texture2:Texture = TextureAtlasManager.getAtlas().getTexture("breadcrumbBusinessBack");
				const scaleTxt2:Scale3Textures = new Scale3Textures(texture2,20, 80, Scale3Textures.DIRECTION_HORIZONTAL);
				bredcrumb2Image = new Scale3Image(scaleTxt2);
				addChild(bredcrumb2Image);

				bredcrumbLabel2 = new Label();
				bredcrumbLabel2.nameList.add("breadcrumb-label2");
				bredcrumbLabel2.text = header2;
				bredcrumbLabel2.y = 15*CommonUtils.scaleValue;
				addChild(bredcrumbLabel2);
			}
			
			if(header3 != "")
			{
				bredcrumbLabel3 = new Label();
				bredcrumbLabel3.nameList.add("breadcrumb-label3");
				bredcrumbLabel3.text = header3;
				bredcrumbLabel3.y = 15*CommonUtils.scaleValue;
				addChild(bredcrumbLabel3);
			}

			const texture1:Texture = TextureAtlasManager.getAtlas().getTexture("InfoBack");
			const scaleTxt1:Scale3Textures = new Scale3Textures(texture1,20, 80, Scale3Textures.DIRECTION_HORIZONTAL);
			bredcrumb1Image = new Scale3Image(scaleTxt1);
			addChild(bredcrumb1Image);
			
			bredcrumbLabel1 = new Label();
			bredcrumbLabel1.nameList.add("breadcrumb-label1");
			bredcrumbLabel1.text = header1;
			bredcrumbLabel1.x = 10*CommonUtils.scaleValue;
			bredcrumbLabel1.y = 15*CommonUtils.scaleValue;
			addChild(bredcrumbLabel1);
		}
		
		override protected function draw():void
		{
			bredcrumb1Image.width = bredcrumbLabel1.width + 40*CommonUtils.scaleValue;
			bredcrumb1Image.height = bredcrumbLabel1.height + 30*CommonUtils.scaleValue;
			
			bredcrumbBackground.width = stage.stageWidth;
			bredcrumbBackground.height = bredcrumbLabel1.height + 30*CommonUtils.scaleValue;
			
			if(bredcrumbLabel2)
			{
				bredcrumbLabel2.x = bredcrumbLabel1.x + bredcrumbLabel1.width + 40*CommonUtils.scaleValue;
				bredcrumb2Image.x = bredcrumbLabel1.x + bredcrumbLabel1.width;
				bredcrumb2Image.width = bredcrumbLabel2.width + 60*CommonUtils.scaleValue;
				bredcrumb2Image.height = bredcrumbLabel1.height + 30*CommonUtils.scaleValue;
				
				//bredcrumb2Image.height = bredcrumbLabel1.height + 10*CommonUtils.scaleValue;
			}
			
			if(bredcrumbLabel3)
			{
				bredcrumbLabel3.x = bredcrumbLabel2.x + bredcrumbLabel2.width + 40*CommonUtils.scaleValue;
			}
			
			this.height = bredcrumb1Image.height;
			
			super.draw();
		}
		
		private function labelTextRenderer():ITextRenderer
		{
			var textRenderer:TextFieldTextRenderer = new TextFieldTextRenderer();
			textRenderer.textFormat = new TextFormat("_sans", 20, 0xFFFFFF);
			return textRenderer;
		}
		
		private function head2TextRenderer():ITextRenderer
		{
			var textRenderer:TextFieldTextRenderer = new TextFieldTextRenderer();
			textRenderer.textFormat = new TextFormat("_sans", 20, 0xCCCCCC);
			return textRenderer;
		}
	}
}